package com.wang.project.controller;

import com.wang.project.common.BaseResponse;
import com.wang.project.common.ErrorCode;
import com.wang.project.common.ResultUtils;
import com.wang.project.exception.BusinessException;
import com.wang.project.model.file.FileQueryParam;
import com.wang.project.model.file.FileUserAvatarUrlVO;
import com.wang.project.model.file.UploadResponse;
import com.wang.project.model.file.FileUploadParam;
import com.wang.project.service.FileService;
import com.wang.project.service.UserService;
import com.wang.project.utils.MinioUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "文件相关接口")
@Slf4j
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileService fileService;

    @Resource
    private UserService userService;

    /**
     * @author: tuimao
     * @date: 2022/5/25 15:32
     * @description: 上传文件
     */
    @PostMapping("/upload")
    public BaseResponse<Boolean> minioUpload(@RequestParam(value = "file") MultipartFile file, FileUploadParam param, HttpServletRequest request) {
        Boolean result = null;
//        FileUploadParam fileUploadParam = new FileUploadParam();
//        fileUploadParam.setType(type);
//        fileUploadParam.setRegion(region);
        try {
            result = fileService.uploadFile(file, param, userService.getLoginUser(request));
        } catch (Exception e) {
            log.error("上传失败", e);
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "上传文件失败");
        }
        return ResultUtils.success(result);
    }

//    @PostMapping("/getUserAvatarUrl")
//    public BaseResponse<FileUserAvatarUrlVO> getUserAvatarUrl(FileQueryParam param,HttpServletRequest request) {
//
//    }
}
